package grpc

import (
	"context"

	"gitee.com/xgotool/sqlite-logs-more/model"
	"gitee.com/xgotool/sqlite-logs-more/protoc"
	"gitee.com/xgotool/sqlite-logs-more/service/logs"
	"github.com/golang/protobuf/ptypes/empty"
	"google.golang.org/protobuf/types/known/emptypb"
)

// 记录pipe日志信息
func (c *GrpcRemote) PipeLog(cnt context.Context, pipe *protoc.Pipe) (*empty.Empty, error) {
	// 设置设备详情
	der, err := getDid(cnt)
	if err != nil {
		return nil, notFond(err)
	}
	if c.Dervice == nil {
		c.Dervice = der
	}
	pipe_log := model.PipeLog{
		Id:      pipe.Id,
		Did:     der.Id,
		Args:    pipe.Args,
		Content: pipe.Content,
	}
	err = logs.PipeCreate(&pipe_log)
	if err != nil {
		return nil, sysErr(err)
	}
	return &emptypb.Empty{}, nil
}
